home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / associateWithKey.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.6 KB  |  140 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Alias|Wavefront Script File MODIFY THIS AT YOUR OWN RISK
  18. //
  19. //  Creation Date:  15 January 1997
  20. //  Author:         cdt
  21. //
  22. //  Procedure Name:
  23. //      associateWithKey
  24. //
  25. //  Description:
  26. //        Procedure to associate a key with an array of strings. This
  27. //        functionality is currently used to determine if menu items
  28. //        need to be deleted and the menu rebuilt. The conditions are
  29. //        that the key is unique, and the value items do not contain a
  30. //        space character.
  31. //
  32. //      See buildPerspLookthruMenu as an example.
  33. //
  34. //  Input Arguments:
  35. //      A unique key to associated with values.
  36. //
  37. //  Return Value:
  38. //      True if the key and values are already stored, false is
  39. //      returned if the key does not exist or the associated values
  40. //      have changed.
  41. //
  42.  
  43. global string $gAssociateKeys[];
  44.  
  45. global string $gAssociateValues[];
  46.  
  47. proc int associateFind( string $key )
  48. {
  49.     global string $gAssociateKeys[];
  50.  
  51.     int $found = false;
  52.  
  53.     int $count = size($gAssociateKeys);
  54.  
  55.     for ($i = 0; $i < $count; $i++) {
  56.         if ($key == $gAssociateKeys[$i]) {
  57.             $found = true;
  58.             break;
  59.         }
  60.     }
  61.  
  62.     return $found ? $i : -1;
  63. }
  64.  
  65. proc associateValueUpdate( int $index, string $value[] )
  66. {
  67.     global string $gAssociateValues[];
  68.  
  69.     int $count = size($value);
  70.  
  71.     for ($i = 0; $i < $count; $i++) {
  72.         if ($i == 0) {
  73.             $gAssociateValues[$index] = $value[$i];
  74.         }
  75.         else {
  76.             $gAssociateValues[$index] =
  77.                 $gAssociateValues[$index]+" "+$value[$i];
  78.         }
  79.     }
  80. }
  81.  
  82. proc int associateValueCompare( string $a1[], string $a2[] )
  83. {
  84.     int $result = true;
  85.  
  86.     int $count = size($a1);
  87.  
  88.     if ($count == size($a2)) {
  89.         for ($i = 0; $i < $count; $i++) {
  90.             if ($a1[$i] != $a2[$i]) {
  91.                 $result = false;
  92.                 break;
  93.             }
  94.         }
  95.     }
  96.     else {
  97.         $result = false;
  98.     }
  99.  
  100.     return $result;
  101. }
  102.  
  103. global proc int associateWithKey( string $key, string $values[] )
  104. {
  105.     global string $gAssociateKeys[];
  106.     global string $gAssociateValues[];
  107.  
  108.     int $match = true;
  109.  
  110.     int $index = associateFind( $key );
  111.  
  112.     if ($index == -1) {
  113.         // Add value
  114.         //
  115.  
  116.         int $count = size($gAssociateKeys);
  117.  
  118.         $gAssociateKeys[$count] = $key;
  119.  
  120.         associateValueUpdate( $count, $values );
  121.  
  122.         $match = false;
  123.     }
  124.     else {
  125.         // Check if the values match
  126.         //
  127.  
  128.         string $associateValues[];
  129.         tokenize($gAssociateValues[$index]," ",$associateValues);
  130.  
  131.         if (!associateValueCompare($associateValues,$values)) {
  132.             associateValueUpdate( $index, $values );
  133.  
  134.             $match = false;
  135.         }
  136.     }
  137.  
  138.     return $match;
  139. }
  140.